package com.igrowing.example.consumer;

import com.igrowing.easyRpc.RpcApplication;
import com.igrowing.easyRpc.bootstrap.ConsumerBootstrap;
import com.igrowing.easyRpc.config.RpcConfig;
import com.igrowing.easyRpc.proxy.ServiceProxyFactory;
import com.igrowing.easyRpc.utils.ConfigUtils;
import com.igrowing.example.common.model.User;
import com.igrowing.example.common.service.UserService;

public class ConsumerExample {

    public static void main(String[] args) {
        // 服务提供者初始化
        ConsumerBootstrap.init();
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();

        // 获取代理 todo mock配置
        UserService userService = null;
        if(!rpcConfig.isMock())
        {
             userService = ServiceProxyFactory.getProxy(UserService.class);
        }
        else {
            userService = ServiceProxyFactory.getMockProxy(UserService.class);
        }
        User user = new User();
        user.setName("ztc");
        // 调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            System.out.println(newUser.getName());
        } else {
            System.out.println("user == null");
        }
    }

//    public static void main(String[] args) {
//        RpcConfig rpc = ConfigUtils.loadConfig(RpcConfig.class, "rpc");
//        System.out.println(rpc);
//
//        UserService userService;
//
//        if(!rpc.isMock())
//        {
//             userService = ServiceProxyFactory.getProxy(UserService.class);
//        }
//        else {
//            userService = ServiceProxyFactory.getMockProxy(UserService.class);
//        }
//        User user = new User();
//        user.setName("ztc");
//        User user1 = userService.getUser(user);
//        if (user1!=null)
//        {
//            System.out.println(user1.getName());
//        }
//        else
//        {
//            System.out.println("user==null");
//        }
//        Short number = userService.getNumber();
//        System.out.println(number);
//    }

}
